import {imageUrl} from "../utils/imageutil"
import {formatTime,is_auth} from "../utils/util"
Page({

  data: {
    imageUrl,
    now_date:'',
    count:0,
    count_economy:0,
    vehicle_qrcode:2,// 1 = 领取过 2 = 未领取
    list:[],
    self:null,
    show_draw:false
  },

  onLoad(options) {
    this.setData({
      now_date:formatTime(new Date(),false,true,true)
    })
  },

  onShow(){
    this.economy()
  },

  economy(){
    getApp().globalData.posts('/api/app/user/sorting/ouyoung_api/economy').then(res=>{
      this.setData({
        ...res.data.data
      })
      if(this.data.vehicle_qrcode==2){
        this.setData({
          show_draw:true
        })
      }
    })
  },

  receiveVehicle(){
    if(this.data.vehicle_qrcode==1){
      this.to_good()
      return
    }
    getApp().globalData.posts('/index.php/api/app/user/sorting/ouyoung_api/receiveVehicle').then(res=>{
      if(res.data.code==1){
        this.setData({
          vehicle_qrcode:1
        })
      }else{
        getApp().showToast(res.data.msg)
      }
    })
  },

  to_good(){
    if (!is_auth(true)) {
      return
    }
    wx.navigateTo({
      url: './good',
    })
  },

  close(){
    this.setData({
      show_draw:false
    })
  },

  onShareAppMessage() {
    let url='/xiche/rank'
    url = encodeURIComponent(url)
    console.log(url)
    return{
      path:'/pages/index/blank?to_id='+wx.getStorageSync('userInfo').id+'&tourl='+url,
      title:'超有幸福',
    }
  },
  
})